# Maintainer: leso-kn <info@lesosoftware.com>
pkgname=baikal
pkgver=0.9.5
pkgrel=0
pkgdesc="Baïkal is a Calendar+Contacts server"
url="https://sabre.io/baikal"
arch="noarch"
license="GPL-3.0-only"
makedepends="
	composer
	rsync
	"
_phpv=82
_php=php$_phpv
_composer="$_php -d memory_limit=512M /usr/bin/composer.phar"
_phpstan="$_php -d memory_limit=512M vendor/phpstan/phpstan/phpstan.phar"
depends="
	$_php-dom
	$_php-openssl
	$_php-pdo
	$_php-session
	$_php-simplexml
	$_php-tokenizer
	$_php-xmlreader
	$_php-xmlwriter
	"
subpackages="
	${pkgname}_sqlite:_sqlite
	"
install="${pkgname}_sqlite.post-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/sabre-io/baikal/archive/refs/tags/$pkgver.tar.gz"
builddir="$srcdir"/Baikal-$pkgver
_grp_www="www-data"

build() {
	mkdir -p build/baikal/Specific/db build/baikal/config
	rsync -av \
		Core html LICENSE README.md composer.json \
		--exclude="*.swp" \
		build/baikal
	$_composer install --no-interaction --no-dev -d build/baikal
}

check() {
	$_composer remove --dev friendsofphp/php-cs-fixer
	$_phpstan analyse Core html
}

package() {
	mkdir -p "$pkgdir"/var/www

	cp -r build/baikal "$pkgdir"/var/www/

	ln -s html "$pkgdir"/var/www/baikal/htm

	chgrp $_grp_www "$pkgdir"/var/www/baikal/config
	chgrp $_grp_www "$pkgdir"/var/www/baikal/Specific/db
}

_sqlite() {
	depends="$pkgname $_php-pdo_sqlite"
	pkgdesc="$pkgdesc (sqlite3 backend)"

	mkdir -p "$subpkgdir"
}

sha512sums="
2e50e51c5c70233d2a508b7bf87a1bcb629c01afc204628c13107cf4929e30fd8594ec85262bf5f7c41a10e5a26253a51ba89320e1bdbfbf99c16e0f4f6d9425  baikal-0.9.5.tar.gz
"
